from pdf2image import convert_from_path
import os
from utils import get_file_info


def do_rmbalnk(base_path, filename):
    # base_path = /static/rmblank/2021200151_1712548660

    pdf_path = os.path.join(base_path, filename)
    print("pdf_path:", pdf_path)
    dpi = 300  # 分辨率，单位为DPI

    # 将PDF转换为图片
    # 输出目录
    file_info = get_file_info(filename)
    """
    static/rmblank/
        example_123452345675869/
            example_123452345675869.pdf
            img/
                1.jpg
                2.jpg
                ...
            example_123452345675869_noblank.pdf
    """
    output_folder = base_path + "/img"  # /static/rmblank/2021200151_1712548660/img
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)
    print("output_folder:", output_folder)

    images = convert_from_path(pdf_path,
                               dpi=dpi,
                               output_folder=output_folder,
                               thread_count=4,
                               fmt="jpg")
    print("the number of images:", len(images))

    return output_folder  # /static/rmblank/2021200151_1712548660/img

